import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/1 20:25
 * @description 画图配合，更容易理解
 */
public class Solution {
    public static void main(String[] args) {

    }
}

class MyCircularDeque {
    int size;
    int capacity;
    ListNode head;
    ListNode tail;
    public MyCircularDeque(int k) {
        size = 0;
        capacity = k;
        head = new ListNode();
        tail = new ListNode();
        head.next = tail;
        tail.pre = head;
    }

    public void addToHead(ListNode node) {
        node.pre = head;
        node.next = head.next;
        head.next.pre = node;
        head.next = node;
    }
    public void addToTail(ListNode node) {
        node.pre = tail.pre;
        node.next = tail;
        tail.pre.next = node;
        tail.pre = node;
    }
    public boolean insertFront(int value) {
        ListNode node = new ListNode(value);
        if (size < capacity) {
            addToHead(node);
            size++;
            return true;
        }
        return false;
    }

    public boolean insertLast(int value) {
        ListNode node = new ListNode(value);
        if (size < capacity) {
            addToTail(node);
            size++;
            return true;
        }
        return false;
    }

    public boolean deleteFront() {
        if (size >= 1) {
            head.next.next.pre = head;
            head.next = head.next.next;
            size--;
            return true;
        }
        return false;
    }

    public boolean deleteLast() {
        if (size >= 1) {
            tail.pre.pre.next = tail;
            tail.pre = tail.pre.pre;
            size--;
            return true;
        }
        return false;
    }

    public int getFront() {
        return size == 0 ? -1 : head.next.val;
    }

    public int getRear() {
        return size == 0 ? -1 : tail.pre.val;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == capacity;
    }
}
class ListNode{
    int val;
    ListNode pre;
    ListNode next;
    public ListNode() {}
    public ListNode(int val) {
        this.val = val;
    }
}
